package com.vizhuo.utils;

import org.springframework.stereotype.Component;

/*
 * 给一个手机号码，判断属于哪个运营商
 * 
 * */
@Component
public class MobilePhoneOperatorUtil {

    public static String CMCC = "1";// 中国移动

    public static String UNICOM = "2";// 中国联通

    public static String TELECOM = "3";// 中国电信

    public static String UNKNWON = "UNKNWON_MOBILE";// 未知

    public static boolean isNumeric(String msg) {
        for (int i = 0; i < msg.length(); i++) {
            if (java.lang.Character.isDigit(msg.charAt(i))) {
                continue;
            }
            return false;
        }
        return true;
    }

    /*
     * @SuppressWarnings("unchecked") public static String getOperater(String
     * phoneNum) { String head3 = ""; String head4 = ""; phoneNum =
     * phoneNum.trim();
     * 
     * if (phoneNum == null || phoneNum.length() < 11) { return UNKNWON; } else
     * { if (phoneNum.startsWith("+")) { phoneNum = phoneNum.substring(1); } if
     * (phoneNum.startsWith("86")) { phoneNum = phoneNum.substring(2); } }
     * 
     * if (phoneNum.length() != 11) { return UNKNWON; }
     * 
     * if (!isNumeric(phoneNum)) { return UNKNWON; }
     * 
     * head3 = phoneNum.substring(0, 3); head4 = phoneNum.substring(0, 4);
     * 
     * Map<String, String> CMCCMap = (Map<String, String>)
     * MemcachedUtils.get("CMCC"); Map<String, String> UNICOMMap = (Map<String,
     * String>) MemcachedUtils.get("UNICOM"); Map<String, String> TELEMap =
     * (Map<String, String>) MemcachedUtils.get("TELECOM");
     * 
     * // 如果memcached中的数据为空，则从数据库中查出，并且将此map放入数据库中 if (CMCCMap == null) {
     * CMCCMap =
     * mobilePhoneOperatorUtil.mobDefenceIService.updateMemcached(MobDefenceConstant
     * .TYPE_CMCC); } if (UNICOMMap == null) { UNICOMMap =
     * mobilePhoneOperatorUtil
     * .mobDefenceIService.updateMemcached(MobDefenceConstant.TYPE_UNICOM); } if
     * (TELEMap == null) { TELEMap =
     * mobilePhoneOperatorUtil.mobDefenceIService.updateMemcached
     * (MobDefenceConstant.TYPE_TELE); }
     * 
     * // 从memcached中获取3个运营商的号段map集合 if (CMCCMap.containsKey(head3) ||
     * CMCCMap.containsKey(head4)) { return CMCC; } else if
     * (UNICOMMap.containsKey(head3) || UNICOMMap.containsKey(head4)) { return
     * UNICOM; } else if (TELEMap.containsKey(head3) ||
     * TELEMap.containsKey(head4)) { return TELECOM; }
     * 
     * 
     * if (head3.equals("135") || head3.equals("136") || head3.equals("137") ||
     * head3.equals("138") || head3.equals("139") || head3.equals("150") ||
     * head3.equals("151") || head3.equals("152") || head3.equals("157") ||
     * head3.equals("158") || head3.equals("159") || head3.equals("178") ||
     * head3.equals("182") || head3.equals("183") || head3.equals("184") ||
     * head3.equals("187") || head3.equals("188") || head3.equals("147")) {
     * return CMCC; } if (head4.equals("1340") || head4.equals("1341") ||
     * head4.equals("1342") || head4.equals("1343") || head4.equals("1344") ||
     * head4.equals("1345") || head4.equals("1346") || head4.equals("1347") ||
     * head4.equals("1348") || head4.equals("1705")) { return CMCC; } if
     * (head3.equals("130") || head3.equals("131") || head3.equals("132") ||
     * head3.equals("145") || head3.equals("155") || head3.equals("156") ||
     * head3.equals("175") || head3.equals("176") || head3.equals("185") ||
     * head3.equals("186") || head4.equals("1709")) { return UNICOM; } if
     * (head3.equals("133") || head3.equals("153") || head3.equals("177") ||
     * head3.equals("180") || head3.equals("181") || head3.equals("189")) {
     * return TELECOM; } if (head4.equals("1349") || head4.equals("1700")) {
     * return TELECOM; }
     * 
     * 
     * return UNKNWON; }
     */
}
